package com.me.mygdxgame.player;

import java.util.ArrayList;
import java.util.List;

public class PlayerGroup {

	private List<Player> players;
	private final boolean isMyGroup;
	private float x, y, xVelocity;
	
	public PlayerGroup(boolean isMine) {
		this.isMyGroup = isMine;
		
		this.xVelocity = 0f;
		
		this.players = new ArrayList<Player>();
	}
	
	public boolean isMyGroup() { return this.isMyGroup; }
	
	public void addPlayer(Player p) {
		p.setGroup(this);
		this.players.add(p);
	}
	
	public void setPosition(float x, float y) {
		this.x = x;
		this.y = y;
		//TODO Arrange players in a formation based on # of players in group
		for (Player p : this.players){
			p.setPosition(this.x, this.y);
		}
	}
	
	public void setXVelocity(float xVel) {
		this.xVelocity = xVel;
		for (Player p : this.players){
			p.setXVelocity(this.xVelocity);
		}
	}
	
	public float getXVelocity() { return this.xVelocity; }
	
	public void dispose() {
		for (Player p : this.players) {
			p.dispose();
		}
	}
	
	public void render(float delta, float cameraXVelocity) {
		for (Player p : this.players){
			p.render(delta, cameraXVelocity);
		}
	}
	
	public List<Player> getPlayers() { return this.players; }
	
	public boolean equals(PlayerGroup pg) {
		for (Player p1 : this.players) {
			for (Player p2 : pg.getPlayers()) {
				if (p1.equals(p2)) {
					return true;
				}
			}
		}
		return false;
	}

	public float getCurrentX() {
		if (this.players != null && this.players.size() > 0) {
			return this.players.get(0).getX();
		}
		return 0;
	}

}
